package com.demo.modalframe4;

import com.demo.modalframe4.listener.CloseWindowListener;
import com.demo.modalframe4.utils.GraphicsUtil;

import javax.swing.*;
import java.awt.*;

public class Frame4 extends JFrame {

    public Frame4() {
        initFrame();

        this.setTitle("Frame 4(parent frame)");
        this.setMinimumSize(new Dimension(GraphicsUtil.Frame_Width, GraphicsUtil.Frame_Height));
        this.setExtendedState(JFrame.MAXIMIZED_BOTH);
        this.addWindowListener(new CloseWindowListener());
    }

    private void initFrame() {
        JButton button = new JButton("Application 模态对话框");
        button.addActionListener(e -> {
            showApplicationModalDialog();
        });

        getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER, 8, 8));
        getContentPane().add(button);
    }

    private void showApplicationModalDialog() {
        JOptionPane.showConfirmDialog(this, "这是一个Application模态对话框",
                "application-modal dialog",
                JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
    }
}
